import React, { Component } from "react";
import CanvasCom from "./CanvasCom";

export default class Box extends Component {
    state = {
        time: 3
    };
    constructor(props) {
        super(props);
    }

    componentDidMount = () => {
        const timer = setInterval(() => {
            const { time } = this.state;
            if (time >= 0) {
                this.setState({ time: time - 1 });
            } else {
                clearInterval(timer);
            }
        }, 1000);
    };

    render() {
        const { time } = this.state;
        return <div>{time >= 0 ? "准备开始" + time : <CanvasCom />}
        </div>;
    }
}
